package com.bbmall.dwd;

import com.bbmall.SparkSessionUtil;
import org.apache.spark.sql.SparkSession;


/**
 * 门店维度表抽取到DWD
 */
public class OdsToDwdDimStore {
    public static void main(String[] args) {
        SparkSession spark = SparkSessionUtil.getSparkSession("ODS_TO_DWD_DIM_STORE");

        try {
            String sql = "INSERT OVERWRITE TABLE dwd.dwd_dim_store PARTITION (dt) " +
                    "SELECT " +
                    "  store_code,    -- 门店编码" +
                    "  store_name,    -- 门店名称" +
                    "  province,      -- 省份" +
                    "  city,          -- 城市" +
                    "  store_type,    -- 门店类型" +
                    "  status,        -- 状态" +
                    "  created_time,  -- 创建时间" +
                    "  updated_time,  -- 更新时间" +
                    "  dt             -- 分区字段" +
                    "FROM ods.ods_store_info " +
                    "WHERE dt = (SELECT MAX(dt) FROM ods.ods_store_info);";

            spark.sql(sql);
            System.out.println("门店维度表（dwd_dim_store）数据抽取完成！");

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (spark != null) spark.stop();
        }
    }
}